/*
 * Powered By [rapid-framework]
 * Web Site: http://www.rapid-framework.org.cn
 * Google Code: http://code.google.com/p/rapid-framework/
 * Since 2008 - 2018
 */

package com.bm.console.pojo;

import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.sys.object.common.page.Page;
import lombok.Data;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.digest.DigestUtils;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Data
public class WebCity extends Page implements java.io.Serializable {
    private static final long serialVersionUID = 1L;

    /**
     * id       db_column: id
     */
    private Long id;

    private Long countryId;
    private Long continentId;
    /**
     * 城市名称(中文)       db_column: chinese_name
     */
    private String chineseName;
    /**
     * 城市名称（英文）       db_column: english_name
     */
    private String englishName;
    /**
     * 和风天气对应该ID
     */
    private String weatherId;
    /**
     * 城市图片       db_column: photo
     */
    private String photo;
    /**
     * 摘要       db_column: description
     */
    private String description;
    /**
     * 城市描述       db_column: content
     */
    private String content;
    /**
     * 城市气候       db_column: climate
     */
    private String climate;
    /**
     * 排序       db_column: sort
     */
    private Integer sort;
    /**
     * 创建时间       db_column: create_time
     */
    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss")
    private Date createTime;
    /**
     * 修改时间       db_column: update_time
     */
    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss")
    private Date updateTime;
    /**
     * 创建者ID       db_column: create_id
     */
    private Long createId;
    /**
     * 修改者ID       db_column: update_id
     */
    private Long updateId;
    /**
     * 状态       db_column: status
     */
    private Boolean status;
    /**
     * seoTitle       db_column: seo_title
     */
    private String seoTitle;
    /**
     * seoKeyword       db_column: seo_keyword
     */
    private String seoKeyword;
    /**
     * seoDescription       db_column: seo_description
     */
    private String seoDescription;

    private String filedata;

    private String fileext;

    private String photos;

    private String basePhotos;

    private String images;

    public String getPhotos() {

        System.err.println("====================base64Photos  get======================"+images+"==");
        if (!org.springframework.util.StringUtils.isEmpty(images)) {
            List<String> list = new ArrayList<>();
            StringBuffer buf = new StringBuffer();
            String[] imgs = images.split(",");
            for (String image : imgs) {
                buf.append(image);
                list.add(buf.toString());
                buf.delete(0, buf.length());
                System.err.println("image:" + image);
            }
            this.photos = Base64.encodeBase64String(JSON.toJSONString(list).getBytes());

            System.err.println(basePhotos);
        }

        return photos;
    }

    public String getBasePhotos() {

        System.err.println("====================base64Photos  get======================"+images+"==");
        if (!org.springframework.util.StringUtils.isEmpty(images)) {
            List<String> list = new ArrayList<>();
            StringBuffer buf = new StringBuffer();
            String[] imgs = images.split(",");
            for (String image : imgs) {
                buf.append(DigestUtils.md5Hex(image)).append("###").append(image);
                list.add(buf.toString());
                buf.delete(0, buf.length());
                System.err.println("image:" + image);
            }
            this.basePhotos = Base64.encodeBase64String(JSON.toJSONString(list).getBytes());

            System.err.println(basePhotos);
        }
        return basePhotos;
    }

}

